﻿@model EraNet.Core.Model.Messages.Notices
@using EraNet.Core.Model.Account;

@{
    Layout = "~/Areas/IMS/Views/Shared/_LayOut.cshtml";
    var memberList = ViewBag.Members;
}
<script src="@Url.Content(" /Scripts/KindEditor/kindeditor.js")" type="text/javascript"></script>
<script src="@Url.Content("/Scripts/My97DatePicker/WdatePicker.js")" type="text/javascript"></script>
<script type="text/javascript">
    
    KE.show(
    {
        id: 'ContentStr',
        imageUploadJson: '/Scripts/KindEditor/asp.net/upload_json.ashx',
        fileManagerJson: '/Scripts/KindEditor/asp.net/file_manager_json.ashx',
        filterMode: false
    });
    function validForm() {
        debugger;
        var Title = $.trim($("#Title").val());
        var ShortTitle = $.trim($("#ShortTitle").val()); ShortTitle
        //编辑器短信内容
        var cont = KE.util.getData('ContentStr');
        var content = KE.util.unescape(cont);
        $("#ContentStr").val(content)

        var ContentStr = $.trim($("#ContentStr").val());
        var StartDate = $.trim($("#StartDate").val());
        var EndDate = $.trim($("#EndDate").val());
       
        if (Title == "") {
            alert("请填写广告标题!"); return false;
        }
        if (ShortTitle == "") {
            alert("请填写广告短标题!"); return false;
        }
        if (ContentStr == "") {
            alert("请填写广告内容!"); return false;
        }
        if (StartDate == "") {
            alert("开始时间不能为空!"); return false;
        }
        if (EndDate == "") {
            alert("结束时间不能为空!"); return false;
        }

        return true;
    }

    function setTxtMember() {
        $.fancybox.close('#selMember_d');
        var memstr = "";
        var memsids = "";
        $("#select2 option").each(function () {
            memstr += $(this).text()+";";
            memsids += $(this).val()+",";
        });
        $("#txt_members").val(memstr);
        $("#memberids").val(memsids)

    }

    $("document").ready(function () {
        //给文本框添加键盘按下并弹起的时间
        $("#txt_seaVal").keyup(function (event) {
            //处理键盘事件
            var myEvent = event || window.event;
            //如果输入的是字母 应该是将文本中最新的信息发送到服务器
            //如果是退格或是删除键 那么就将文本中最新的信息发送给服务器
            var keyCode = myEvent.keyCode;
            if (keyCode >= 65 && keyCode <= 90 || keyCode == 8 || keyCode == 46) {
                //1 得到文本框中的内容
                var wordtext = $("#txt_seaVal").val();

                var dataPara = "&memberName=" + wordtext;
                $.ajax({
                    async: false,
                    type: "POST",
                    url: "/IMS/Messages/seachMember",
                    dataType: "json",
                    data: dataPara,
                    success: function (data) {
                        var objList = eval(data);
                        for (var i = 0; i < objList.length; i++) {
                            $("#select1 option").remove();
                            $("#select1").append("<option ondblclick=\"moveRight(this)\" value='" + objList[i].Id + "'>" + objList[i].Names + "<" + objList[i].IDCard +"></option>");
                        }

                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert('请求出现异常，请稍后再试'); reloadcode_stu();
                    }

                });

            }
        });
    })

    function moveRight(item) {
        $("#select1 option[value='" + item.value + "']").remove();
        if ($("#select2 option[value='" + item.value + "']").length > 0) {
            alert("选择学员已存在。");
            return;
        }
        $("#select2").append("<option ondblclick=\"moveLeft(this)\" value='" + item.value + "'>" + item.text + "</option>");
    }

    function moveLeft(item) {
        
        $("#select2 option[value='" + item.value + "']").remove();
        $("#select1").append("<option  ondblclick=\"moveRight(this)\" value='" + item.value + "'>" + item.text + "</option>");
    }

    function radCheage(item) {
        if (item == 1) {
            $("#afancybox").click();
            $("#txt_members").show();
        }
        else {
            $("#txt_members").hide();
        }
    }
</script>


<div style="overflow-x:visible;" class="wrapper">
<!-- Left column/section -->
<div class="column width6 first" style="display:inline">
<div class="box box-info"><h7>发布公告</h7></div>
@using (Html.BeginForm())
{
<input  type="hidden"  id="memberids" name="memberids" />
    <p>
<label class="required" for="Title">标题:</label><br/>
@Html.TextBoxFor(p => p.Title, new { @class = "half", @onchange = "btnClick(this)",@MaxLength="30" }) 
</p>
<p>
<label class="required" for="ShortTitle">短标题:</label><br/>
@Html.TextBoxFor(p => p.ShortTitle, new { @class = "half", @MaxLength = "20" })
</p>
<p>
<label class="required" for="StartDate">开始时间:</label><br/>
@Html.TextBoxFor(p => p.StartDate, new { @maxlength = 50,@class = "half", onfocus = "new WdatePicker(this,true,'default')", onclick = "WdatePicker()" })
</p>
<p>
<label class="required" for="EndDate">结束时间:</label><br/>
@Html.TextBoxFor(p => p.EndDate, new { @maxlength = 50,@class = "half", onfocus = "new WdatePicker(this,true,'default')", onclick = "WdatePicker()" })
</p>
    <p>
<label  for="ShortTitle">接收人:<span><input type="radio" id="allUser" name="radMember" checked="checked"  value="all" onclick="radCheage(0)" /><b>所有</b></span>
<span>
<a id="afancybox" class="fancybox" href="###selMember_d"></a><input type="radio" id="selUser" name="radMember" onclick="radCheage(1)"  value="sel" /><b>选择</b></span> </label><br/>
<textarea id="txt_members" name="txt_members"  style="width:500px;height:50px; display:none"  ></textarea>
</p>
<p>
<label class="required" for="ContentStr">内容</label><br/>
<textarea id="ContentStr" name="ContentStr"  style="width:800px;height:400px" ></textarea>
</p>
<p class="rbox" style="text-align:center">
<input type="submit" class="btn"  value="发布公告" onclick="return validForm()" /> 
</p>
}
</div>
@Html.Action("_RightNav", "Common")
<!-- End of Right column/section -->
</div>


<div id="selMember_d" style="display: none">
    <div>
    <div style="display:inline"><input type="text" id="txt_seaVal" style="width:250px;" /></div>
    <div style="display:inline">已选接收人</div>
    </div>
    <div style="display:inline">
    <select name="select2" multiple="multiple" id="select1" size="10" style="width:260px;">
        @foreach (Member m in memberList)
        {
             <option value="@m.Id" ondblclick="moveRight(this)" >@m.Names<@m.IDCard></option>
        }
    </select>
    <div style="display:inline">
     <select name="select21" multiple="multiple" id="select2" size="10" style="width:260px;">
    </select>
    </div>
    </div>
    <div style="float:inherit">
     <input type="button" id="btnOk" value="确定" onclick="setTxtMember()" name="btnSubmit" />
     </div>
</div>